let fs = require('fs');

let fileName = './1.txt';

fs.exists(fileName, function (result) {

    if (result) {
        fs.readFile(fileName, function (err, data) {
            console.log(data.toString());
        })
    }

});


let promise = new Promise(function (resolve, reject) {

    setTimeout(function () {
        resolve('我是成功状态');//把 promise状态改变

    }, 200);

});

// console.log(promise);

// promise.then(function(x){
//     console.log('我是成功的输出:'+x);
// },function(y){
//     console.log('我是失败的输出:'+y);
// })


function promiseFun() {

    let promise = new Promise(function (resolve, reject) {

        setTimeout(function () {
            resolve('我是成功状态');//把 promise状态改变

        }, 200);

    });
    return promise;
}
async function demo() {

    let result = await promiseFun();

    console.log(result);

    console.log('我是函数内部的最下面1');
    
    console.log('我是函数内部的最下面2');

    console.log('我是函数内部的最下面3');

}



// demo();

// console.log('我是外层的下部输出');


function readFileByPromise(filename){

    return new Promise(function(resolve,reject){
        fs.readFile(fileName,function(err,data){
            if(err){
                reject(err.message);
            }else{
                resolve(data.toString());
            }
        })
    })

}

async function handleFile(fileName){

    let content = await readFileByPromise(fileName);

    console.log(content);
}

handleFile('./1.txt');